package jgl.vajra.management.part.mine.fragment;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import jgl.vajra.management.R;
import jgl.vajra.management.bean.MyTeamAllListBean;
import jgl.vajra.management.databinding.FragmentMyTeamAllBinding;
import jgl.vajra.management.manager.AccountManager;
import jgl.vajra.management.part.mine.contract.MyTeamAllListContract;
import jgl.vajra.management.part.mine.pop.MyTeamAllPop;
import jgl.vajra.management.part.mine.viewModel.MyTeamAllListViewModel;
import jgl.vajra.management.widget.bean.BaseListData;
import jgl.vajra.management.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.management.widget.interfaces.RefreshRecyclerLoadStatusListener;
import jgl.vajra.management.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.management.widget.mvvm.view.BaseMVVMFragment;
import jgl.vajra.management.widget.recyclerView.RefreshRecyclerNetConfig;
import jgl.vajra.management.widget.utils.UIUtils;

@CreateViewModel(MyTeamAllListViewModel.class)
public class MyTeamAllListFragment extends BaseMVVMFragment<MyTeamAllListViewModel, FragmentMyTeamAllBinding> implements MyTeamAllListContract.View {

    private int type;
    private SingleTypeBindingAdapter adapter;
    private MyTeamAllPop myTeamAllPop;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_my_team_all;
    }

    @Override
    public void initView() {
        mBinding.setView(this);
        type = getArguments().getInt("type");
        mBinding.setData(type);

       /* // 不可嵌套滑动
        mBinding.recyclerView.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.recyclerView.setFocusableInTouchMode(false);
        //设置布局管理器
        adapter = new SingleTypeBindingAdapter(mActivity, null, R.layout.item_my_team);
        mBinding.recyclerView.setAdapter(adapter);
        mBinding.recyclerView.firstLoad();
        requestNetData();*/


        mBinding.recyclerView.setRefreshRecyclerNetConfig(new RefreshRecyclerNetConfig() {
            @Override
            public Observable getNetObservable(Map<String, Object> map, int action) {
                map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
                map.put("tag", type);
                return mViewModel.getMyTeamAllList(map);
            }
        });


        adapter = new SingleTypeBindingAdapter(mActivity, null, R.layout.item_my_team);
        mBinding.recyclerView.setAdapter(adapter);
        mBinding.recyclerView.setIsDataObject(true);
        mBinding.recyclerView.setRefreshLoaderMore(false, false);
        mBinding.recyclerView.setRefreshRecyclerLoadStatusListener(new RefreshRecyclerLoadStatusListener<BaseListData<MyTeamAllListBean>>() {
            @Override
            public void onSucceed(BaseListData<MyTeamAllListBean> data, int action) {
                for (int i = 0; i < data.data.size(); i++) {
                    data.data.get(i).type = type;
                }

                mBinding.recyclerView.setRefreshLoaderMore(true, true);

                mBinding.recyclerView.requestNetObjectSuccess(data.data, action);
            }

            @Override
            public void onError(String errorInfo, int errorCode, int action) {
                super.onError(errorInfo, errorCode, action);
//                mBinding.recyclerView.requestNetError(errorInfo, errorCode);
            }
        });
        mBinding.recyclerView.firstLoad();

    }

    private void requestNetData() {
        Map<String, Object> map = new HashMap<>();
        map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
        map.put("tag", type);
        mViewModel.getMyTeamAllList(map);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }

    @Override
    public void returnMyTeamAllList(List<MyTeamAllListBean> data) {

    }

    //加入时间
    @Override
    public void onJoinTime() {
        //ToastUtils.showShort("加入时间");
    }

    //加入地点
    @Override
    public void onJoinLocation() {
       // ToastUtils.showShort("加入地点");
    }

    //机械设备
    @Override
    public void onMechanicalEquipment() {
        //ToastUtils.showShort("机械设备");
    }

    //累计接单
    @Override
    public void onCumulativeReceipt() {
        //ToastUtils.showShort("累计接单");
    }

    //累计下单
    @Override
    public void onCumulativeOrders() {
        //ToastUtils.showShort("累计下单");
    }

    //岗位认证
    @Override
    public void onCertification() {
        /*ToastUtils.showShort("岗位认证");
        if (myTeamAllPop == null)
            myTeamAllPop = new MyTeamAllPop(mActivity);
        myTeamAllPop.setMyTeamAllListener((itemData, name) -> {
        });
        myTeamAllPop.showPopupWindow(mBinding.llcView);*/
    }
}
